package com.txcb.lib.base.utils;

import java.security.MessageDigest;

/**
 * @author : Lambert
 * date   : 2020/10/29 3:11 PM
 */
public class MD5Util {

   public static String setString(String content){
       try {
           MessageDigest digest = MessageDigest.getInstance("MD5");
           byte[] bytes = digest.digest(content.getBytes());
           StringBuilder sb = new StringBuilder();
           for (byte b : bytes) {
               int c = b & 0xff; //负数转换成正数
               String result = Integer.toHexString(c); //把十进制的数转换成十六进制的书
               if(result.length()<2){
                   sb.append(0); //让十六进制全部都是两位数
               }
               sb.append(result);
           }
           return sb.toString(); //返回加密后的密文
       } catch (Exception ex) {
           ex.printStackTrace();
           return "";
       }
   }
}
